package yf.mall.dysdk.model.request.video;

import com.alibaba.fastjson.JSONObject;
import com.yf.response.RRException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import yf.mall.utils.StringUtil;
import yf.mall.vo.app.dy.DyVideoVO;

import java.util.HashMap;
import java.util.Map;

/**
 * 好用的话可以购买 应该靠谱
 * https://pay.vzzw.com/detail/1003.html
 */
@Slf4j
public class DyVideoRequest1 extends DyVideoBaseRequest {


    public DyVideoRequest1() {
        this.url = "https://api.vzzw.com/api/get/jiexi";
        this.method = HttpMethod.GET;
    }


    @Override
    public DyVideoVO parseVideo(String shareVideo) {
        Map map = new HashMap();
        map.put("appid", "wxdc4de83533d3cb61");
        map.put("content", shareVideo);
        Long current = System.currentTimeMillis();
        String res = super.parseVideo(map);
        current = System.currentTimeMillis() - current;
        log.info("请求去水印接口,url:{},res:{}", url, res);
        if (StringUtil.isBlank(res)) {
            log.error("请求去水印接口失败,url:{},res:{}", url, res);
            throw new RRException("去水印请求失败!");
        }
        JSONObject jsonObject = JSONObject.parseObject(res);
        if (!jsonObject.get("code").equals(0) || !jsonObject.containsKey("data")) {
            log.error("请求去水印接口失败,url:{},res:{}", url, res);
            throw new RRException("去水印请求失败!");
        }
        JSONObject data = jsonObject.getJSONObject("data");
        if (!data.containsKey("downurl")) {
            log.error("请求去水印接口失败,url:{},res:{}", url, res);
        }
        return new DyVideoVO(data.getString("downurl"), null, data.getString("image"), data.getString("title"),current);
    }
}
